home *** CD-ROM | disk | FTP | other *** search
- ======== Exploring the PSP - by Brent Ashley =========
-
- DOS maintains various data structures to help it to organize
- a running machine's memory. One of these structures is the
- Program Segment Prefix, which is a collection of information DOS
- builds for an executing program. The following discussion and the
- accompanying program will give you all you need to access and
- interpret the information stored in your program's PSP.
-
- The PSP is a 256-byte area which is reserved in memory
- immediately before your program is loaded and run by the command
- shell (usually COMMAND.COM). Its structure follows, along with
- typical uses of the information it contains. Offsets are in hex,
- byte counts in decimal, and remember that intel processors store
- numbers with lowest bytes first, ie 1234:5678 is stored as 78 56
- 34 12.
-
- ------------------------
-
- OFFSET 0 - 2 Bytes
-
- There will always be the bytes CD 20 here - this is an INT 20h
- call (terminate program). It's here so programs can jump to
- this location to terminate - not recommended, but it makes sense
- that programs which jump to an uninitialised (zero) address
- should be made to terminate in this way.
-
- OFFSET 2 - 2 Bytes
-
- This is the segment address of the last paragraph of memory
- allocated to the program.
-
- OFFSET 5 - 5 Bytes
-
- There is a far call to the DOS function dispatcher here. This
- is here only for CP/M compatibility and is never used.
-
- OFFSET A - 4 Bytes
- OFFSET E - 4 Bytes
- OFFSET 12 - 4 Bytes
-
- These are the Segment:Offset Addresses to which control is
- passed:
-
- - upon termination of the program.
- - when Control-Break is pressed.
- - when a critical error is encountered.
-
- OFFSET 16 - 2 Bytes
-
- The segment address of this program's parent program's PSP is
- stored here.
-
- OFFSET 18 - 20 Bytes
-
- A table of 20 file handles is stored here. Any program needing
- more than the default 20 file handles will need to use INT 21h
- function 67h to set the handle count to a number more than 20
- (but no more than FILES= in CONFIG.SYS). This will cause DOS
- to allocate a new file handle table of the size requested. See
- Offsets 2E, 30 also.
-
- OFFSET 2C - 2 Bytes
-
- DOS provides each executable program with its own copy of the
- active Environment Strings at program load time. This is the
- segment address of this program's copy. The environment strings
- block contains a list of strings, each terminated by a 00 byte,
- with a further 00 byte at the end of the list. At the end of the
- environment strings, there is a 2-byte User Program signature
- which, when set to 1 (01 00), signifies the program's full path
- specification can be found in the following bytes, teminated
- with a null (00) byte.
-
- OFFSET 2E - 2 Bytes
-
- This is the number of file handles in the current handle table.
-
- OFFSET 30 - 4 Bytes
-
- Segment:Offset address of the file handle table, either the one
- here in the PSP, or the one allocated with INT 21h svc 67h.
-
- OFFSET 5C - 16 Bytes
- OFFSET 6C - 16 Bytes
-
- There are two unopened File Control Blocks constructed here as
- part of the program load process, based on the command line
- entered when the current progam was invoked. It's interesting
- to note that DOS has already parsed the drive, filename and
- extension and placed it here, but only if there is no path
- information included, since FCBs are a throwback from when DOS
- didn't have a heirarchical directory structure.
-
- OFFSET 80 - 1 Byte
- OFFSET 81 - 127 Bytes
-
- The length of the command line entered after the program name
- when the program was invoked is stored here, followed by the
- command line itself. The default Disk Transfer Area for this
- program is also here, so unless your program sets its own
- (which most do), the command line information could be
- overwritten. You might want to get the command line information
- from here because QB uppercases it and trims it before passing
- it to you via COMMAND$.
-
- ------------------------
-
- The accompanying program, PSP.BAS, shows how you can access and
- interpret the PSP. Remember that when using it in the QB
- development environment, the PSP it will be looking at is that of
- the environment. A good test for the program will be to invoke it
- as follows:
-
- PSP A:FILENAME.EXT B:OUTFILE.TST
-
- Have Fun!
-
- -----
- Brent
- -----
-
- <EOF>
-
-